import keyCodeMap from './keyCode'

export function isDom(el) {
  return el instanceof HTMLElement
}

export function toKeyCode(key) {
  if (isNaN(Number(key)) && typeof keyCodeMap[key] !== 'number') {
    throw new Error(`AzKeyboardMan: Got an invalid key or keyCode: ${JSON.stringify(key)}`)
  }
  return isNaN(Number(key)) ? keyCodeMap[key] : Number(key)
}

export function toKeyOrKeyCode(key) {
  if (typeof keyCodeMap[key] === 'undefined') {
    throw new Error(`AzKeyboardMan: Got an invalid key or keyCode: ${JSON.stringify(key)}`)
  }
  return keyCodeMap[key]
}
